<template>
  <div class="whole">
    <el-form
      label-width="100px"
      label-position="right"
      ref="ss"
      :model="studentScore"
      :rules="rules"
    >
      <el-form-item label="名称" prop="name">
        <el-input v-model="studentScore.name"> </el-input>
      </el-form-item>
      <el-form-item label="在线分数" required prop="onlineScore">
        <el-input v-model="studentScore.onlineScore"></el-input>
      </el-form-item>
      <el-form-item label="课堂成绩" required prop="classScore">
        <el-input v-model="studentScore.classScore"></el-input>
      </el-form-item>
      <el-form-item label="学号" required prop="code">
        <el-input v-model="studentScore.code"></el-input>
      </el-form-item>
      <el-button-group>
        <el-button type="primary" @click="insert">保存</el-button>
        <el-button type="secondary" @click="reset">重置</el-button>
      </el-button-group>
    </el-form>
  </div>
</template>

<script>
// import New from './components/New.vue';
export default {
  name: "First",
  components: {
    // New,Old,
  },
  props: {
    sampleP: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      sampleD: "value",
      studentScore: {
        scoreId: 0,
        onlineScore: null,
        name: null,
        code: null,
        classScore: 0,
      },
      rules: {
        name: [{ required: true, message: "请输入信息", trigger: "blur" }],
        onlineScore: [
          { pattern: /^[0-9]*$/, message: "只能输入数字", trigger: "blur" },
        ],
        code: [{ validator: this.validateCode, trigger: "blur" }],
      },
      // rules: {
      //     username: [
      //         {required: true,   message: '请输入账号', trigger: 'blur'},
      //         {pattern: /^\w+$/, message: '请输入字母/数字/下划线', trigger: ['blur','change']},
      //         {required:true, validator:this.validateItem ,trigger:'blur'}
      //         ],
      //     password: [
      //         {required: true, message: '请输入密码', trigger: 'blur'},
      //         ],
      //     }
      rout: [
        {
          id: 1,
          path: "/index",
          name: "Index",
          pid: -1,
          level: 1,
          isDir: false,
          children: [],
        },
        {
          id: 2,
          path: null,
          name: "LeaveGroup",
          pid: -1,
          level: 1,
          isDir: true,
          children: [
            {
              id: 3,
              path: "/leaveApply",
              name: "Index",
              pid: 2,
              level: 2,
              isDir: false,
              children: [],
            },
            {
              id: 4,
              path: "/leaveAudit",
              name: "Index",
              pid: 2,
              level: 2,
              isDir: false,
              children: [],
            },
          ],
        },
        {
          id: 5,
          path: null,
          name: "newsGroup",
          pid: -1,
          level: 1,
          isDir: true,
          children: [
            {
              id: 6,
              path: null,
              name: "newsSon",
              pid: 5,
              level: 2,
              isDir: true,
              children: [
                {
                  id: 7,
                  path: null,
                  name: "/newsSonSon",
                  pid: 6,
                  level: 3,
                  isDir: false,
                  children: [],
                },
              ],
            },
          ],
        },
      ],
    };
  },
  computed: {
    // sampleC() {
    //     return this.sampleD+'--';
    // }
  },

  created() {},
  mounted() {},
  methods: {
    sampleM() {},
    insert() {
      this.$notify.info("将要发送信息：" + JSON.stringify(this.studentScore));
      this.$refs["ss"].validate((valid) => {
        if (valid) {
          this.$http({
            method: "put",
            url: "/studentScore",
            data: this.studentScore,
          }).then(
            (res) => {
              this.$message.warning(JSON.stringify(res.data));
              //this.total = res.data.total;
              //this.newsResults = res.data.results;
            },
            (error) => {
              console.log(error.response.status);
            }
          );
        } else {
          this.$message.warning("发送数据不合法");
        }
      });
    },
    reset() {
      this.$refs["ss"].resetFields();
    },

    validateCode(rules, value, callback) {
      console.log("value : " + value);
      if (value.includes("aa")) {
        callback(new Error("code值不能包含禁用aa字符串"));
      } else {
        callback();
      }
    },
  },
  watch: {
    // sampleC(newValue, oldValue) {
    //
    // }
  },
};
</script>

<style scoped>
/*<style lang='scss' scoped>*/
.whole {
  background-color: rgba(99, 208, 71, 0.71);
  display: flex;
  justify-content: center;
}
form {
  flex: 0.3;
  margin-top: 20px;
  background-color: rgba(73, 244, 62, 0.71);
  border-radius: 3px;
  padding: 18px 24px 12px 3px;
}
</style>
